<%--
  Created by IntelliJ IDEA.
  User: 19635
  Date: 2022/3/28
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
<%--    导入Jquery--%>
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<div margin:0px auto;>
<form action="#" id="formLogin" method="post" >
    用户名:<input type="text" placeholder="请输入用户名" name="username"/><br/>
    密 &ensp;&ensp;码:<input type="password" placeholder="请输入密码" name="password"/><br/>
    <div>
        验证码:<input type="text" name="captcha" />
        <img src="${pageContext.request.contextPath}/captcha" id="img" width="80px" height="20px" /><br/>
    </div>
    <input type="button" id="login" value="登录" />
</form>
</div>
</body>
<script>
    $(function () {
        //点击图片刷新
        $("#img").click(function () {
            //定义一个路径
            this.src="${pageContext.request.contextPath}/captcha?time="+new Data().getTime();

        });
        //单击点击时间表单中的数据---序列化---将用户信息提交过去
        $("#login").click(function () {
            //出发ajax请求
            $.ajax({
                url:"/SSM/user/login",
                data:$("#formLogin").serialize(),//提交数据
                type:"post",
                success:function (resp) {
                    if (resp.code==1){
                        alert(resp.msg);
                        window.location.href="${pageContext.request.contextPath}/user/findAll";

                    }
                    if (resp.code == 0) {
                        alert(resp.msg);
                    }
                },
                dataType:"json"
            });

        });

        });
</script>
</html>
